﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reactive.Concurrency;
using System.Reactive.PlatformServices;

namespace RxTestbed
{
    class EventProcessingTut
    {
        static void Main(string[] args)
        {
            /*foreach (var s in GetInput())
                Console.WriteLine(s);*/

            var src = GetInput().ToObservable(NewThreadScheduler.Default);

            var res = src.Window(3, 1);

            int i = 0;
            res.ForEachAsync(w =>
                                 {
                                     int j = i++;
                                     Console.WriteLine("new window " + j + " created");
                                     w.Subscribe(x => Console.WriteLine(" " + x + " in " + j));
                                 });

            /*
            var res = from s in src
                      group s by s.Length;


            res.ForEachAsync(g =>
                                 {
                                     Console.WriteLine("New group with length = " + g.Key);
                                     g.Subscribe(x => Console.WriteLine(" " + x + " member of " + g.Key));
                                 });
            */
            //src.ForEachAsync((System.Action<string>)Console.WriteLine);


        }

        static IEnumerable<string> GetInput()
        {
            while (true)
                yield return Console.ReadLine();
        }
    }
}
